<?php
// 订单
// 
namespace app\api\controller;
use app\api\utils\Utils;

class Order
{

    //提交订单
    public function addOrder ()
    {
        $userInfo = [
            'userInfo'=>['username', 'userPhone', 'personalNo']
        ];
        $field = ['token', 'onSellCode', 'totalPrice', 'totalNum',
            'userName', 'userPhone', 'useTime', $userInfo];
        $data = [
            'orderCode'    => '201700200',
            'payOrderCode' => 'P2017002001',
            'payOrderTime' => '20170717132215',
            'payTime'      => 1800,
        ];
        return Utils::validateRequestMethod(['post'])
            ->validateParams(true, [])
            ->response($data);
    }

    /**
     * 微信支付
     * @return [type] [description]
     */
    public function payOrderWX ()
    {
        $field = ['token', 'payOrderCode', 'payOrg', 'spbillCreateIp'];
        
        $data = [
            'prepayId'    => '201700200',
            'payOrderCode' => 'P2017002001',
            'payOrderTime' => '20170717132215',
            'payTime'      => 1800,
        ];
        return Utils::validateRequestMethod(['post'])
            ->validateParams(true, [])
            ->response($data);
    }

    //支付订单状态查询接口
    public function payOrderstatus ()
    {
        $field = ['token', 'payOrderCode'];
        $data = ['payStatus'=>'00'];
        return Utils::validateRequestMethod(['post'])
            ->validateParams(true, [])
            ->response($data);
    }

    //支付退款接口(微信)
    public function orderReturnWX ()
    {
        $field = ['token', 'payOrderCode', 'payOrg'];
        $data = ['退款成功'];
        return Utils::validateRequestMethod(['post'])
            ->validateParams(true, [])
            ->response($data);
    }

    //订单列表查询
    public function orderList ()
    {
        $field = ['token', 'limit', 'offset'];
        $data = [
            [
                'orderCode'   => 'p123121031131',
                'orderStatus' => '00',
                'imgPath'     => '',
                'totalNum'    => '3',
                'totalPrice'  => '300',
            ],
            [
                'orderCode'   => 'p123121031131',
                'orderStatus' => '00',
                'imgPath'     => '',
                'totalNum'    => '3',
                'totalPrice'  => '300',
            ],
            [
                'orderCode'   => 'p123121031131',
                'orderStatus' => '00',
                'imgPath'     => '',
                'totalNum'    => 3,
                'totalPrice'  => '300',
            ],
        ];
        return Utils::validateRequestMethod(['post'])
            ->validateParams(true, [])
            ->response($data, ['total'=>3]);
    }

    //订单详情查询
    public function orderDetail ()
    {
        $field = ['token', 'orderCode'];
        $data  = [
            'orderCode'   => 'p123121031131',
            'orderStatus' => '00',
            'imgPath'     => '',
            'totalNum'    => 3,
            'totalPrice' => '300',
            'productName' => '崇圣寺三塔门门票',
            'sellPrice'  => '100.00元',
            'showPrice'  => '100.00元',
            'useTips'    => '2017年7月25日前使用',
            'orderTime'  => '20170718132200',
            'useTime'    => '20170719',
            'limitDayNum' => 7,
            'prompt'      => '其他项目需自费',
            'openTime'    => '夏季7:00-19:00 冬季7:30-18:30',
            'payOrderTime' => '20170717132215',
            'thirdPayOrderCode' => '54136845',
        ];
        return Utils::validateRequestMethod(['post'])
            ->validateParams(true, [])
            ->response($data);
    }

    //取消订单
    public function cancelOrder ()
    {
        $field = ['token', 'orderCode'];
        $data = ['取消成功'];
        return Utils::validateRequestMethod(['post'])
            ->validateParams(true, [])
            ->response($data);
    }

    //退款状态
    public function refundStatus ()
    {
        $field = ['token', 'orderCode'];
        $data = [
            'totalPrice' => '300.00',
            'userAccount' =>  '18745421643',
            'arriveTime'  => '20170718235500'
        ];
        return Utils::validateRequestMethod(['post'])
            ->validateParams(true, [])
            ->response($data);
    }

    //退款流程
    public function refundFlow ()
    {
        $field = ['token', 'orderCode'];
        $data = [
            [
                'refundStatus' => 'XXX审核通过',
                'tips' =>  '已将退款申请提交支付宝',
                'createTime'  => '20170717015500'
            ],
            [
                'refundStatus' => '支付宝已受理',
                'tips' =>  '您的退款已被支付宝成功受理',
                'createTime'  => '20170717015000'
            ],
            [
                'refundStatus' => '退款成功',
                'tips' =>  '支付宝已将198元转至您的支付宝账户',
                'createTime'  => '20170718235500'
            ],
        ];
        return Utils::validateRequestMethod(['post'])
            ->validateParams(true, [])
            ->response($data);
    }

}